package com.kateba.android.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.view.MotionEvent;
import android.view.View;

public class DrawView extends View
  implements View.OnTouchListener
{
  Point m_LastPos;
  String m_szText = "";
  Paint paint = new Paint();
  Paint paintCur = new Paint();
  Paint paintKeys = new Paint();
  List<Point> points = new ArrayList();

  public DrawView(Context paramContext)
  {
    super(paramContext);
    setFocusable(true);
    setFocusableInTouchMode(true);
    this.m_LastPos = new Point();
    this.paint.setColor(-1);
    this.paint.setAntiAlias(false);
    this.paintCur.setColor(-65536);
    this.paintCur.setAntiAlias(true);
    this.paintKeys.setColor(-16711936);
    this.paintKeys.setAntiAlias(true);
    this.paintKeys.setStrokeWidth(1.0F);
  }

  public void AddKey(char paramChar)
  {
    this.m_szText += paramChar;
    invalidate();
  }

  public void Clear()
  {
    this.m_szText = "";
    this.m_LastPos.x = (int) 0.0F;
    this.m_LastPos.y = (int) 0.0F;
    this.points.clear();
    invalidate();
  }

  public void UpdateCursor(int paramInt1, int paramInt2, boolean paramBoolean)
  {
    Point localPoint1 = this.m_LastPos;
    localPoint1.x += paramInt1;
    Point localPoint2 = this.m_LastPos;
    localPoint2.y += paramInt2;
    if (this.m_LastPos.x < 0.0F)
      this.m_LastPos.x = (int) 0.0F;
    if (this.m_LastPos.y < 0.0F)
      this.m_LastPos.y = (int) 0.0F;
    if (paramBoolean)
    {
      Point localPoint3 = new Point();
      localPoint3.x += this.m_LastPos.x;
      localPoint3.y += this.m_LastPos.y;
      this.points.add(localPoint3);
    }
    invalidate();
  }

  public void onDraw(Canvas paramCanvas)
  {
    paramCanvas.drawCircle(this.m_LastPos.x, this.m_LastPos.y, 5.0F, this.paintCur);
    Iterator localIterator = this.points.iterator();
    int i = 0;
    int j= 0;
    int k= 0;
    int m= 0;
    int n = 0;
    int i2 = 0;
    if (!localIterator.hasNext())
    {
      i = paramCanvas.getWidth() / 30;
      j = paramCanvas.getHeight() / 20;
      k = paramCanvas.getWidth() % 30 / 2;
      m = j * 2;
      n = k;
      i2 = m;
    }
    for (int i4 = 0; ; i4++)
    {
      if (i4 >= this.m_szText.length())
      {
       // return;
        Point localPoint = (Point)localIterator.next();
        paramCanvas.drawPoint(localPoint.x, localPoint.y, this.paint);
        break;
      }
      paramCanvas.drawText(this.m_szText, i4, i4 + 1, n, i2, this.paintKeys);
      int i1 = 0;
      n += i;
      if (i1 > paramCanvas.getWidth())
      {
        i1 = k;
        i2 += j;
      }
      int i5 = j * 5;
      
//      if (i3 <= i5)
//        continue;
      int i3 = m;
      this.m_szText = "";
      invalidate();
    }
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    return false;
  }
}